<?php
/**
 * 快速排序算法
 * author  yajun
 * @parame  array
 * @return  array
 * @Time    2013-7-5
 */
function quicksort($array)
{
	if(count($array) > 1)
	{
		$m = $array[0];
		$arr1 = array();
		$arr2 = array();
		$len = count($array);
		for ($i = 1; $i < $len; $i++)
		{
			if($array[$i] > $m)
			{
				$arr1[] = $array[$i];
			}
			else
			{
				$arr2[] = $array[$i];
			}
		}	
		$new1 = array();
		$new2 = array();
		$new1 = quicksort($arr1);
		$new2 = quicksort($arr2);
		return array_merge($new1,array($m),$new2);
	}
	else
	{
		return $array;
	}
}
$array = quicksort(array(1,654,132,3213,13,21,1514));
var_dump($array);